import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
from tensorflow.keras.datasets import mnist
import matplotlib.pyplot as plt
import numpy as np

# 模拟最大池化过程
def max_pooling_2d(input_matrix, pool_size=(2, 2)):
    pool_height, pool_width = pool_size
    output_height = input_matrix.shape[0] // pool_height
    output_width = input_matrix.shape[1] // pool_width
    
    output = np.zeros((output_height, output_width))
    
    for i in range(output_height):
        for j in range(output_width):
            pool_region = input_matrix[
                i*pool_height:(i+1)*pool_height,
                j*pool_width:(j+1)*pool_width
            ]
            output[i, j] = np.max(pool_region)
    
    return output

# 示例
input_map = np.random.rand(4, 4)
print("输入特征图:")
print(input_map)
print("\n2x2最大池化结果:")
print(max_pooling_2d(input_map))